/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jaotwinker;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
import java.util.ArrayList;
/**
 *
 * @author Grayson
 */
public class Item {
    
    public int AOID;
    public String Name;
    public int QL;
    public String ItemType;
    public int icon;
    public String slot;
    public ArrayList Requirements;
    public ArrayList Skills;
    public String[] Slots;
    
    
    public void Item() {}
    
    public void set(int aoid, String name, int ql, String type) {
        AOID=aoid; Name=name; QL=ql; ItemType=type;
        Requirements = new ArrayList();
        Skills = new ArrayList();
        Slots = new String[100];
        // More as requirements demand
    }
    
    public Element getXML(Document dom) {
        Element e = dom.createElement("Item");
        e.setAttribute("AOID", String.valueOf(AOID));
        e.setAttribute("Name", Name);
        e.setAttribute("QL", String.valueOf(QL));
        e.setAttribute("ItemType", ItemType);
        e.setAttribute("Icon", String.valueOf(icon));
        e.setAttribute("Slot", slot);
        
        for (int i=0; i<Requirements.size(); i++) {
            Requirement r = (Requirement)Requirements.get(i);
            Element f = r.getXML(dom);
            e.appendChild(f);
        }
        
        for (int j=0; j<Skills.size(); j++) {
            Skill s = (Skill)Skills.get(j);
            Element g = s.getXML(dom);
            e.appendChild(g);
        }
        return e;
    }
    
    public boolean testItem(ExcludedItems ei) {
        // Run tests to see whether this item should be added to cleaned copy
        if(AOID==274718) {
            System.out.println("Found item.");
        }
        if(icon==0) return false;
        if(Skills.size()<=0) return false;
        if(ItemType.equalsIgnoreCase("Misc")) return false;
        if(ItemType=="NPC") return false;
        if(ItemType=="Tower") return false;
        if(slot=="") return false;
        for(int i=0;i<Requirements.size();i++) {
            Requirement r = (Requirement)Requirements.get(i);
            if(r.name.equalsIgnoreCase("GMLevel") || r.name.equalsIgnoreCase("NPCFamily")) return false;
        }
        for(int j=0;j<ei.ids.size();j++) {
            int eiid = (Integer)ei.ids.get(j);
            if(AOID==eiid) return false;
        }
        if(Name.contains("Symbiant") && AOID<220236) return false; // these are all erroneous entries corrected later
        
        return true;
    }
    
    public void sortSlots() {
        Slots = slot.split(", ");
    }
    
    public int getSkill(String skill) {
        for(int i=0;i<Skills.size();i++) {
            Skill s = (Skill)Skills.get(i);
            if(s.name.equalsIgnoreCase(skill)) { return Integer.parseInt(s.value); }
        }
        return -1000;
    }
}
